﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using Common;
using CNCSoft.EData;

namespace CNCSoft.ErpApps.TMS.longGiaoVu
{
    public partial class frmEditTinhTrangInvoiceKhoaHoc : Form
    {
        SqlConnection conn = new SqlConnection(GlobalVariable.WSInfo.ConnectionString);
        DataSet ds = new DataSet();
        string companyid = GlobalVariable.WSInfo.CompanyID;

        public frmEditTinhTrangInvoiceKhoaHoc()
        {
            InitializeComponent();
        }

        private void frmEditTinhTrangInvoiceKhoaHoc_Load(object sender, EventArgs e)
        {
            LoadData();
        }

        private void btnCapNhat_Click(object sender, EventArgs e)
        {
            UpdateData();
            LoadData();
        }

        private void btnBoQua_Click(object sender, EventArgs e)
        {
            ds.RejectChanges();
        }

        #region "Coding"
        private void LoadData()
        {
            try
            {
                // Load all invoice_khoahoc to grid
                LoadAllInvoiceKhoaHoc(companyid);
                gridControl_Data.DataSource = ds.Tables["TableAllInvoiceKhoaHoc"];
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void LoadAllInvoiceKhoaHoc(string companyid)
        {
            try
            {
                if (ds.Tables["TableAllInvoiceKhoaHoc"] != null)
                    ds.Tables["TableAllInvoiceKhoaHoc"].Clear();
                string sql = @"usp_AllInvoiceKhoaHoc @madonvi  = '" + companyid + "'";
                SqlDataAdapter da = new SqlDataAdapter(sql, conn);
                da.Fill(ds, "TableAllInvoiceKhoaHoc");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void UpdateData()
        {
            try
            {
                string sql = @"select * from Invoice_KhoaHoc";
                SqlDataAdapter da = new SqlDataAdapter(sql, conn);
                DataHelper.buildDataCommands(ref da);
                da.Update(ds, "TableAllInvoiceKhoaHoc");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        #endregion
    }
}
